package pl.edu.pw.ee.buildcity.charts.models;

import com.googlecode.charts4j.Color;
import com.googlecode.charts4j.Data;
import com.googlecode.charts4j.Plot;
import com.googlecode.charts4j.Plots;
import pl.edu.pw.ee.buildcity.domain.BuildStatus;

import static com.googlecode.charts4j.Color.GREEN;
import static com.googlecode.charts4j.Color.RED;
import static pl.edu.pw.ee.buildcity.domain.BuildStatus.SUCCEEDED;

/**
 * @author Mateusz
 * @since 2010-02-17
 */
public class BarChartModel implements ChartModel {

	private double duration;
	private BuildStatus buildStatus;

	public BarChartModel(BuildStatus buildStatus, double duration) {
		this.buildStatus = buildStatus;
		this.duration = duration;
	}

	@Override
	public Plot asPlot() {
		Data data = new Data(duration);
		Color color = getColorForBuildResult(buildStatus);
		return Plots.newBarChartPlot(data, color);
	}

	private Color getColorForBuildResult(BuildStatus buildStatus) {
		return buildStatus == SUCCEEDED ? GREEN : RED;
	}
}
